package com.free.bsf.metric.dal.auto;


import java.util.Date;
import com.free.bsf.core.util.ConvertUtils;
import com.free.bsf.core.db.DbConn;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import lombok.*;
import com.free.bsf.metric.model.auto.*;

/**
 * tb_front_metric 表自动dal映射,不要手工修改
 * 
 * @author 车江毅
 * @since 2023-04-03 16:21:07
 * 自动生成: https://gitee.com/makejava/EasyCode/wikis/
 */
public class tb_front_metric_base_dal {

    public boolean add(DbConn conn, tb_front_metric_model model) {
        val par = new Object[]{
            /***/
            model.create_time,
            /***/
            model.update_time,
            /**核心脚本*/
            model.main_script,
            /**工具脚本*/
            model.tool_script,
            /**正在使用否*/
            model.isUse,
            /**版本名*/
            model.version_name,
            /**变更记录*/
            model.remark
        };
        int rev = conn.executeSql("insert into tb_front_metric(create_time,update_time,main_script,tool_script,isUse,version_name,remark)" +
                "values(?,?,?,?,?,?,?)", par);
        return rev == 1;
    }

    public boolean edit(DbConn conn, tb_front_metric_model model) {
       val par = new Object[]{
           /***/
            model.create_time,
           /***/
            model.update_time,
           /**核心脚本*/
            model.main_script,
           /**工具脚本*/
            model.tool_script,
           /**正在使用否*/
            model.isUse,
           /**版本名*/
            model.version_name,
           /**变更记录*/
            model.remark,
            model.id
        };
        int rev = conn.executeSql("update tb_front_metric set create_time=?,update_time=?,main_script=?,tool_script=?,isUse=?,version_name=?,remark=? where id=?", par);
        return rev == 1;

    }

    public boolean delete(DbConn conn, Integer id) {
        val par = new Object[]{id};
        String Sql = "delete from tb_front_metric where id=?";
        int rev = conn.executeSql(Sql, par);
        if (rev == 1) {
            return true;
        } else {
            return false;
        }
    }

    public tb_front_metric_model get(DbConn conn, Integer id) {
        val par = new Object[]{id};
        val stringSql = new StringBuilder();
        stringSql.append("select s.* from tb_front_metric s where s.id=?");
        val ds = conn.executeList(stringSql.toString(), par);
        if (ds != null && ds.size() > 0) {
            return createModel(ds.get(0));
        }
        return null;
    }

    public ArrayList<tb_front_metric_model> list(DbConn conn) {
        val rs = new ArrayList<tb_front_metric_model>();
        val stringSql = new StringBuilder();
        stringSql.append("select s.* from tb_front_metric s ");
        val ds = conn.executeList(stringSql.toString(), new Object[]{});
        if (ds != null && ds.size() > 0) {
            for (Map<String, Object> dr : ds) {
                rs.add(createModel(dr));
            }
        }
        return rs;
    }

    public tb_front_metric_model createModel(Map<String, Object> dr) {
        val o = new tb_front_metric_model();
        /***/
        if (dr.containsKey("id")) {
            o.id = ConvertUtils.convert(dr.get("id"),Integer.class);
        }
        /***/
        if (dr.containsKey("create_time")) {
            o.create_time = ConvertUtils.convert(dr.get("create_time"),Date.class);
        }
        /***/
        if (dr.containsKey("update_time")) {
            o.update_time = ConvertUtils.convert(dr.get("update_time"),Date.class);
        }
        /**核心脚本*/
        if (dr.containsKey("main_script")) {
            o.main_script = ConvertUtils.convert(dr.get("main_script"),String.class);
        }
        /**工具脚本*/
        if (dr.containsKey("tool_script")) {
            o.tool_script = ConvertUtils.convert(dr.get("tool_script"),String.class);
        }
        /**正在使用否*/
        if (dr.containsKey("isUse")) {
            o.isUse = ConvertUtils.convert(dr.get("isUse"),Integer.class);
        }
        /**版本名*/
        if (dr.containsKey("version_name")) {
            o.version_name = ConvertUtils.convert(dr.get("version_name"),String.class);
        }
        /**变更记录*/
        if (dr.containsKey("remark")) {
            o.remark = ConvertUtils.convert(dr.get("remark"),String.class);
        }
        return o;
    }
}


